package ${package.Controller};

import com.enba.boot.core.base.Result;
import ${package.Service}.${table.serviceName};
import javax.annotation.Resource;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import ${package.Entity}.${entity};
import org.springframework.web.bind.annotation.RequestMapping;
<#if restControllerStyle>
import org.springframework.web.bind.annotation.RestController;
<#else>
import org.springframework.stereotype.Controller;
</#if>
<#if superControllerClassPackage??>
import ${superControllerClassPackage};
</#if>

/**
 * <p>
 * ${table.comment!}
 * </p>
 *
 * @author ${author}
 * @since ${date}
 */
<#if restControllerStyle>
@RestController
<#else>
@Controller
</#if>
@RequestMapping("<#if package.ModuleName?? && package.ModuleName != "">/${package.ModuleName}</#if>/<#if controllerMappingHyphenStyle>${controllerMappingHyphen}<#else>${table.entityPath}</#if>")
<#if kotlin>
class ${table.controllerName}<#if superControllerClass??> : ${superControllerClass}()</#if>
<#else>
<#if superControllerClass??>
public class ${table.controllerName} extends ${superControllerClass} {
<#else>
public class ${table.controllerName} {
</#if>

  @Resource
  private ${table.serviceName} ${table.entityPath}Service;

  /**
  * 查询所有接口
  *
  * @return list
  */
  @GetMapping
  public Result<List<${entity}>> findAll() {
      return Result.success(${table.entityPath}Service.list());
  }

  /**
  * 根据id查询数据接口
  *
  * @param id id
  * @return result
  */
  @GetMapping("/{id}")
  public Result<${entity}> findOne(@PathVariable Integer id) {
      return Result.success(${table.entityPath}Service.getById(id));
  }

  /**
  * 分页查询接口
  *
  * @param pageNum nume
  * @param pageSize size
  * @return result
  */
  @GetMapping("/page")
  public Result<Page<${entity}>> findPage(@RequestParam Integer pageNum,@RequestParam Integer pageSize) {
      QueryWrapper<${entity}> queryWrapper = new QueryWrapper<>();
      return Result.success(${table.entityPath}Service.page(new Page<>(pageNum, pageSize), queryWrapper));
  }

  /**
  * 新增和更新接口
  *
  * @param ${table.entityPath} ${table.entityPath}
  * @return result
  */
  @PostMapping
  public Result<Boolean> save(@RequestBody ${entity} ${table.entityPath}) {
      return Result.success(${table.entityPath}Service.saveOrUpdate(${table.entityPath}));
  }

  /**
  * 删除接口
  *
  * @param id id
  * @return result
  */
  @DeleteMapping("/{id}")
  public Result<Boolean> delete(@PathVariable Integer id) {
      return Result.success(${table.entityPath}Service.removeById(id));
  }

  /**
  * 批量删除接口
  *
  *
  * @param ids ids
  * @return result
  */
  @PostMapping("/del/batch")
  public Result<Boolean> deleteBatch(@RequestBody List<Integer> ids) {
      return Result.success(${table.entityPath}Service.removeByIds(ids));
   }
}
</#if>
